{include file="public/header" /}
<link rel="stylesheet" href="/static/admin/addons/builder/css/base.css" media="all">
<style>
    .layui-form-item {
        margin-bottom: 15px !important;
        clear: both;
        *zoom: 1;
    }
</style>
<body>
<form action="{:url('save')}" class="layui-form" id="form">
    {include file="public/arguments" /}
    <input type="hidden" name="id" value="{$Request.get.id|default=''}">
    <input type="hidden" name="pid" value="{$Request.get.pid|default=0}">
    <div class="layui-fluid layui-anim layui-anim-downbit">
        <div class="layui-card">
            <div class="layui-card-body" style="padding: 15px;">
                <div class="layui-row" style="padding-top: 8px;">
                    {if $p_title }
                    <div class="layui-form-item">
                        <label class="layui-form-label">上级菜单</label>
                        <div class="layui-input-block">
                            <input type="text" value="{$p_title}" class="layui-input" disabled />
                        </div>
                    </div>
                    {/if}
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red">*</span>菜单名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" placeholder="请输入菜单名称"
                                   value="{$info?$info.title:''}" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red">*</span>菜单简称</label>
                        <div class="layui-input-block">
                            <input type="text" name="sub_title" placeholder="请输入菜单简称"
                                   value="{$info?$info.sub_title:''}" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red">*</span>菜单节点</label>
                        <div class="layui-input-block">
                            <input type="text" id="name" name="name" placeholder="例如：menu/index "
                                   value="{$info?$info.name:''}" autocomplete="off" class="layui-input" />
                        </div>
                        <div class="layui-form-mid layui-word-aux">请使用驼峰命名</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red">*</span>菜单图标</label>
                        <div class="layui-input-block">
                            <input type="text" name="css" value="{$info?$info.css:''}" autocomplete="off" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red">*</span>排序</label>
                        <div class="layui-input-block">
                            <input type="number" name="sort" placeholder="请输入排序"
                                   value="{$info?$info.sort:'0'}" class="layui-input" />
                        </div>
                    </div>
                    {if !isset($info)}
                    <div class="layui-form-item">
                        <label class="layui-form-label">自动构建Controller</label>
                        <div class="layui-input-block">
                            <input type="radio" name="autoController" value="" lay-filter="controller" title="关闭" checked>
                            <input type="radio" name="autoController" value="1" lay-filter="controller" title="单控制器">
                            <input type="radio" name="autoController" value="2" lay-filter="controller"
                                   title="控制器+自动构建Table">
                        </div>
                        <div class="layui-form-mid layui-word-aux">开启后，将自动生成控制器</div>
                    </div>
                    <div class="controller" style="display:none;">
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span class="x-red">* </span>控制器名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="className" placeholder="请输入控制器名称" autocomplete="off" class="layui-input auto_name" />
                            </div>
                            <div class="layui-form-mid layui-word-aux">控制器的名称，列如Test</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span class="x-red">* </span>命名空间</label>
                            <div class="layui-input-block">
                                <input type="text" name="classNamespace" placeholder="请输入命名空间"
                                       value="app\admin\controller\" autocomplete="off" class="layui-input" />
                            </div>
                            <div class="layui-form-mid layui-word-aux">完整的命名空间，无需包含类名称</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">自动构建Model</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="autoModel" lay-skin="switch" lay-filter="model" lay-text="是|否" value="1">
                        </div>
                        <div class="layui-form-mid layui-word-aux">开启后，将自动生成模型类</div>
                    </div>
                    <div class="model" style="display:none;">
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span class="x-red">* </span>模型名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="modelName" placeholder="请输入模型名称" autocomplete="off" class="layui-input auto_name" />
                            </div>
                            <div class="layui-form-mid layui-word-aux">模型的名称，列如Test</div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label"><span class="x-red">* </span>命名空间</label>
                            <div class="layui-input-block">
                                <input type="text" name="modelNamespace" placeholder="请输入命名空间"
                                       value="app\common\model\" autocomplete="off" class="layui-input" />
                            </div>
                            <div class="layui-form-mid layui-word-aux">完整的命名空间，无需包含类名称</div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label"><span class="x-red">* </span>表名</label>
                            <div class="layui-input-block">
                                <input type="text" name="dbName" placeholder="请输入表名" class="layui-input db_name" />
                            </div>
                            <div class="layui-form-mid layui-word-aux">Model类对应的数据库表名</div>
                        </div>
                    </div>
                    {/if}
                </div>
            </div>
        </div>
    </div>
    {include file="public/submit" /}
</form>
</body>
{include file="public/footer" /}
<script>
    layui.use('form', function () {
        var form = layui.form;
        $("#name").blur(function () {
            var value = $(this).val();
            var split = value.split('/');
            if (split[0]) {
                $(".auto_name").val(cap(split[0]));
                $(".db_name").val(split[0]);
            } else {
                $(".auto_name").val('');
                $(".db_name").val('');
            }
        });

        function cap(str) {
            return str.replace(/([a-z])/, function (match, value) {
                return value.toUpperCase();
            })
        }

        form.on('radio(controller)', function (data) {
            if (data.value) {
                if (data.value == '2') {
                    layer.msg('自动生成控制器+自动构建Table依赖数据表注释，请按结构合理配置')
                }
                $(".controller").show();
            } else {
                $(".controller").hide();
            }
        });

        form.on('switch(model)', function (data) {
            if (data.elem.checked) {
                $(".model").show();
            } else {
                $(".model").hide();
            }
        });


    });
</script>
</html>